import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

public class MainMap {

	/**
	 * @param args
	 * @throws SQLException
	 */
	// public static final String mainDB =
	// "jdbc:postgresql://203.185.65.41:5432/Traffic_Data";
	public static final String mainDB = "jdbc:postgresql://localhost:5432/Traffic_Data";

	public static void main(String[] args) throws SQLException, IOException {
		Util.deleteLog();
		double[][][] cube;

		// ++++++++++++++++ [Map matching] ++++++++++++++++
		/**
		 * Test for 1 point
		 * */

		// GPSpnt x = new GPSpnt(null, 0, "", 13.764276, 100.537749, 0, 0, "");
		// MapMatchAlgo d = new MapMatchAlgo();
		// MapMatchResult res = d.mapmatch(x);
		// System.out.println(res.toString());

		/**
		 * Map all points in tables and update a result to current record Update
		 * every time when there are new data in pastPointGPS
		 * */
		// MapMatcher map = new MapMatcher();
		// System.out.println("Start map matching");
		// map.start();

		// ++++++++++++++++ [DateTimes matrix preparation] ++++++++++++++++
		/**
		 * Fetch linkID data => sorted and unique => if(exist) then write into
		 * text file else then read from file
		 * */
	
		ArrayList<LinkCharateristic> linkObject = new ArrayList<LinkCharateristic>();
		TimePeriodGrouping timeGroup = new TimePeriodGrouping();
		linkObject = timeGroup.setUpLinkID(Config.LINKID_PATH);
		GenCubeMatrix gen = new GenCubeMatrix(linkObject);
		cube = gen.setSizeArray();
		// printTest(timeGroup, cube);
		// ++++++++++++++++ [Calculation] ++++++++++++++++
		cube = timeGroup.groupSourceIDperLink(cube, gen);

		// for (int i = 0; i < cube.length; i++) {
		// for (int j = 0; j < cube[0].length; j++) {
		// for (int j2 = 0; j2 < cube[0][0].length; j2++) {
		// if (cube[i][j][j2] > 0) {
		// System.out.println(cube[i][j][j2]);
		// }
		// }
		// }
		// }
		new CalculateTimeUsed(cube, RouteDestination.TU_to_VM_route, gen);
		
		// Util.writeLog("Group by 7days of week and sub group by time with 30 min interval");
	}

	// =============================================================================
	public static void printTest(TimePeriodGrouping timeGroup, double[][][] cube)
			throws IOException {
		// Print data in ArrayList that contain link_id, time_stamp, row_id,
		// timeClass,Source_id
		timeGroup.printResult();
		// Print size of 3D array
		// Day size : 7 time size : 49 link size : 472
		System.out.println("Day size : " + cube.length + " time size : "
				+ cube[0].length + " link size : " + cube[0][0].length);
	}
	// =============================================================================
}
